package com.ofwiki.demo.scheduler.common;

/**
 * @author HuangJS
 * @date 2021-12-27 9:45 上午
 */
public class JobHelper {
   
    public static Long getJobId() {
        JobContext jobContext = JobContext.getJobContext();
        if (jobContext == null) {
            return null;
        }
        return jobContext.getJobId();
    }
    
    public static String getJobParam() {
        JobContext jobContext = JobContext.getJobContext();
        if (jobContext == null) {
            return null;
        }
        
        return jobContext.getJobParam();
    }
    

    public static boolean handleSuccess(){
        return handleResult(JobContext.SUCCESS, null);
    }
    public static boolean handleSuccess(String handleMsg) {
        return handleResult(JobContext.SUCCESS, handleMsg);
    }
    public static boolean handleFail(){
        return handleResult(JobContext.FAIL, null);
    }
    public static boolean handleFail(String handleMsg) {
        return handleResult(JobContext.FAIL, handleMsg);
    }
    
    public static boolean handleResult(int handleCode, String handleMsg) {
        JobContext jobContext = JobContext.getJobContext();
        if (jobContext == null) {
            return false;
        }
        
        jobContext.setHandleCode(handleCode);
        if (handleMsg != null) {
            jobContext.setHandleMsg(handleMsg);
        }
        return true;
    }
}
